package com.echo.blog.business.sys.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.echo.blog.business.sys.dao.SysUserMapper;
import com.echo.blog.business.sys.model.SysUser;
import com.echo.blog.business.sys.service.ISysUserService;
import com.echo.model.constant.ConstantUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author chentl123
 * @since 2019-05-28
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {

    @Override
    public SysUser getUserById(Integer userId) {
        return this.baseMapper.selectById(userId);
    }

    @Override
    public SysUser userValid(String username, String password) {
        QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
        wrapper.eq("username", username)
                .eq("password", password);
        return this.getOne(wrapper);
    }

    @Override
    public String getPasswordByUserName(String userName) {
        String password = "";
        QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
        wrapper.eq("username", userName);
        SysUser sysUser = this.getOne(wrapper);
        if (sysUser != null) {
            password = sysUser.getPassword();
        }
        return password;
    }

    @Override
    public SysUser getUserByName(String username) {
        QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
        wrapper.eq("username", username);
        return this.getOne(wrapper);
    }

    @Override
    public SysUser getUserByThirdId(Integer thirdId) {
        QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
        wrapper.eq(ConstantUtils.Public.THIRD_ID, thirdId);
        SysUser sysUser = this.getOne(wrapper);
        return sysUser;
    }
}
